package com.pcs.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.pcs.controller.BirthdayController;
import com.pcs.controller.CommonController;
import com.pcs.controller.ContactController;
import com.pcs.controller.RemindController;
import com.pcs.controller.UserController;
import com.pcs.controller.BlogController;
import com.pcs.model.Blog;
import com.pcs.model.Contact;
import com.pcs.model.Remind;
import com.pcs.model.User;

public class PcsConfig  extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("a_little_config.txt");
		me.setDevMode(true);
		
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", CommonController.class);
		me.add("/user", UserController.class);
		me.add("/contact", ContactController.class);
		me.add("/remind", RemindController.class);
		me.add("/blog", BlogController.class);
		me.add("/birthday", BirthdayController.class);
		
	}

	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		me.add(c3p0Plugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("user", User.class);	// 映射blog 表到 Blog模型
		arp.addMapping("contact", Contact.class);
		arp.addMapping("remind", Remind.class);
		arp.addMapping("blog", Blog.class);
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}
	
	
	public static void main(String[] args) {
		JFinal.start("WebRoot", 8081, "/", 1);
	}

}
